<template>
  <div>
    <el-card class="box-card" style="text-align: center;margin: -55px auto;background: #f6f6f7;">
      <el-container>
        <app-header></app-header>
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right" style="width: 1200px;margin: 0 auto;">
            <el-breadcrumb-item>您所在的位置：</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>特色资源</el-breadcrumb-item>
            <el-breadcrumb-item>水循环遥感产品列表</el-breadcrumb-item>
          </el-breadcrumb>
        <el-row style="width: 1200px;margin: 20px auto;">
          <el-col :span="4">
            <el-menu
              default-active="1-1"
              :default-openeds="openeds"
              class="el-menu-vertical-demo"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#ffd04b"
            >
              <el-submenu index="1">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>水循环遥感产品</span>
                </template>
              <el-menu-item index="1-1" @click="menuClick('1-1')">
                <i class="el-icon-document"></i>
                <span slot="title">蒸散发</span>
              </el-menu-item>
              <el-menu-item index="1-2" @click="menuClick('1-2')">
                <i class="el-icon-setting"></i>
                <span slot="title">土壤含水量</span>
              </el-menu-item>
              </el-submenu>
            </el-menu>
          </el-col>
          <el-col :span="18" style="margin-left: 30px;" v-if="flag=='1'">
            <el-row>
              <el-col :span="8" v-for="item in tableData" :key="item.id">
                <el-link :underline="false" @click="colClick(item.id)">
                <el-card :body-style="{ padding: '5px' }">
                  <img :src="imgUrl" class="image">
                  <div style="padding: 14px;">
                    <span>{{item.name}}</span>
                  </div>
                </el-card>
                </el-link>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="18" style="margin-left: 30px;" v-if="flag=='2'">
            <el-row>
              <el-col :span="8" v-for="item in tableData" :key="item.id">
                <el-link :underline="false" @click="colClick(item.id)">
                  <el-card :body-style="{ padding: '5px' }">
                    <img :src="imgUrl" class="image">
                    <div style="padding: 14px;">
                      <span>{{item.name}}</span>
                    </div>
                  </el-card>
                </el-link>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
          <div class="box-card" style="margin-top: 35px;">
            <el-pagination
              background
              :current-page="currentPage"
              :page-sizes="pageSizes"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalCount"
              style="float: right;margin-top: -15px;"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>

        </el-main>
        <el-footer>Footer</el-footer>
      </el-container>
    </el-card>
  </div>
</template>

<script>
import myHeader from '../../components/myHeader'
import {selectPageUploadEntity} from '@/api/news'
import {encrypt} from '@/util/rsaEncrypt'
export default {
  data () {
    return {
      activeIndex1: '1',
      newList: {},
      fits: ['fill', 'contain', 'cover', 'none', 'scale-down'],
      url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
      src: 'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg',
      openeds: ['1'],
      flag: '1',
      /* 装载查询后的数据 */
      upload: {},
      imgUrl: require('@/assets/slt.jpg'),
      // 总数据
      tableData: [],
      // 默认显示第几页
      currentPage: 1,
      // 总条数，根据接口获取数据长度(注意：这里不能为空)
      totalCount: 1,
      // 个数选择器（可修改）
      pageSizes: [6, 9, 18, 36],
      // 默认每页显示的条数（可修改）
      pageSize: 6,
      type: 0
    }
  },
  components: {
    'app-header': myHeader
  },
  created () {
    this.menuClick('1-1')
    this.pageUploadClick()
  },
  methods: {

    // 点击方法
    pageUploadClick () {
      this.getData(this.pageSize, this.currentPage, this.type)
    },
    // 分页
    // 每页显示的条数
    handleSizeChange (pageSize) {
      // 改变每页显示的条数
      this.pageSize = pageSize
      // 点击每页显示的条数时，显示第一页
      this.getData(pageSize, 1, this.type)
      // 注意：在改变每页显示的条数时，要将页码显示到第一页
      this.currentPage = 1
    },
    // 显示第几页
    handleCurrentChange (current) {
      // 改变默认的页数
      this.currentPage = current
      // 切换页码时，要获取每页显示的条数
      this.getData(this.pageSize, current, this.type)
    },
    // 将页码，及每页显示的条数以参数传递提交给后台
    getData (pageSize, current, type) {
      // 这里使用axios，使用时请提前引入
      const page = {
        // 每页显示的条数
        size: this.pageSize,
        // 显示第几页
        current: current,
        // 活动id
        type: this.type
      }
      console.log(page)
      selectPageUploadEntity(page).then(res => {
        if (res.data.status === 1005) {
          this.tableData = res.data.data.records
          this.totalCount = res.data.data.total
        } else {
          this.tableData = []
          this.totalCount = 0
          this.$message.error('出错了！')
        }
      })
    },
    /* 点击信息跳转详情页 */
    colClick (v) {
      const id = encrypt(v + '')
      localStorage.setItem('id', id)
      this.$router.push({path: '/details'})
    },
    menuClick (v) {
      if (v === '1-2') {
        this.type = 2
        this.flag = 2
        this.currentPage = 1
        this.pageUploadClick()
      }
      if (v === '1-1') {
        this.type = 1
        this.flag = 1
        this.currentPage = 1
        this.pageUploadClick()
      }
    }
  }
}
</script>

<style scoped>
.el-header, .el-footer {
  background-color: #1a75ce;
  text-align: center;
  line-height: 60px;
}
.el-menu{
  border: none;
}
.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
}

body > .el-container {
  margin-bottom: 40px;
}

.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
</style>
